<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="result"></div>
<script>
    var source = new EventSource("/stream2")

    var i = 0;
    source.onmessage = function (event) {
        console.log(event)
        console.log(event.data)
        i++;
        if (i===10){
            source.close()
            console.log("接收到十次，自动关闭")
        }
    };
</script>
</body>
</html>